<template>
  <aside class="app-sidebar">
    <nav>
      <ul>
        <li><router-link to="/">控制台</router-link></li>
        <li class="dropdown">
          <span @click="toggleDropdown('userManagement')">
            用户管理
            <i class="arrow" :class="{ 'arrow-down': activeDropdown === 'userManagement' }"></i>
          </span>
          <ul class="dropdown-content" v-if="activeDropdown === 'userManagement'">
            <li><router-link to="/users">用户列表</router-link></li>
          </ul>
        </li>
        <li class="dropdown">
          <span @click="toggleDropdown('contentManagement')">
            角色与权限管理
            <i class="arrow" :class="{ 'arrow-down': activeDropdown === 'contentManagement' }"></i>
          </span>
          <ul class="dropdown-content" v-if="activeDropdown === 'contentManagement'">
            <li><router-link to="/content/articles">角色管理</router-link></li>
            <li><router-link to="/content/categories">权限管理</router-link></li>
          </ul>
        </li>
        <li class="dropdown">
          <span @click="toggleDropdown('dishManagement')">
            菜品管理
            <i class="arrow" :class="{ 'arrow-down': activeDropdown === 'dishManagement' }"></i>
          </span>
          <ul class="dropdown-content" v-if="activeDropdown === 'dishManagement'">
            <li><router-link to="/dishes/types">菜品类型管理</router-link></li>
            <li><router-link to="/dishes/info">菜品信息管理</router-link></li>
          </ul>
        </li>
        <li class="dropdown">
          <span @click="toggleDropdown('tableManagement')">
            餐桌管理
            <i class="arrow" :class="{ 'arrow-down': activeDropdown === 'tableManagement' }"></i>
          </span>
          <ul class="dropdown-content" v-if="activeDropdown === 'tableManagement'">
            <li><router-link to="/tables">餐桌管理</router-link></li>
          </ul>
        </li>
        <li class="dropdown">
          <span @click="toggleDropdown('orderManagement')">
            订单管理
            <i class="arrow" :class="{ 'arrow-down': activeDropdown === 'orderManagement' }"></i>
          </span>
          <ul class="dropdown-content" v-if="activeDropdown === 'orderManagement'">
            <li><router-link to="/orders/list">订单管理</router-link></li>
          </ul>
        </li>
        <li class="dropdown">
          <span @click="toggleDropdown('goodsManagement')">
            货物管理
            <i class="arrow" :class="{ 'arrow-down': activeDropdown === 'goodsManagement' }"></i>
          </span>
          <ul class="dropdown-content" v-if="activeDropdown === 'goodsManagement'">
            <li><router-link to="/goods/orders">货物订单管理</router-link></li>
            <li><router-link to="/goods/warehouse">仓库管理</router-link></li>
          </ul>
        </li>
      </ul>
    </nav>
  </aside>
</template>

<script setup lang="ts">
import { ref } from 'vue';

const activeDropdown = ref<string | null>(null);

const toggleDropdown = (dropdown: string) => {
  activeDropdown.value = activeDropdown.value === dropdown ? null : dropdown;
};
</script>

<style scoped>
.app-sidebar {
  position: fixed;
  width: 200px; /* Increased width */
  background-color: #f4f4f4;
  padding: 30px 0;
  height: calc(100vh - 20px);
  overflow-y: auto;
}

.app-sidebar ul {
  list-style: none;
  padding: 0;
}

.app-sidebar li {
  margin-bottom: 5px; /* Reduced margin */
  text-align: center; /* Center text */
}

.app-sidebar a, .app-sidebar span {
  text-decoration: none;
  color: #333;
  display: block;
  padding: 10px 0; /* Adjust padding */
  cursor: pointer;
  transition: background-color 0.3s ease; /* Smooth transition */
}

.app-sidebar a:hover, .app-sidebar span:hover {
  background-color: #09b4c5;
  color: #fff;
}

.dropdown {
  position: relative;
}

.dropdown span {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 5px;
}

.arrow {
  display: inline-block;
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 5px solid #333;
  transition: transform 0.3s ease;
}

.arrow-down {
  transform: rotate(180deg);
}

.dropdown-content {
  background-color: #e8e8e8;
  min-width: 200px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  margin-top: 5px;
  border-left: 3px solid #09b4c5;
}

.dropdown-content li {
  margin: 0;
}

.dropdown-content a {
  padding: 8px 16px;
  text-align: center;
  background-color: #f4f4f4;
  margin: 2px 0;
}

.dropdown-content a:hover {
  background-color: #09b4c5;
  color: #fff;
}
</style> 